/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package datamodel;

import java.io.Serializable;
import java.util.Set;
import javax.persistence.*;

/**
 *
 * @author eXtreme
 */
@Entity
@DiscriminatorColumn(name="groupname", discriminatorType= DiscriminatorType.STRING)
public abstract class SystemUser implements Serializable {

    // -----------------------
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "user_id")
    private Long id;
    protected String email;
    protected String name;
    protected String surname;
    @Column(name = "pwd")
    protected String password;
    @OneToMany(mappedBy = "wroteBy")
    @OrderBy("id DESC")
    protected Set<Post> wrote;
    // -----------------------    

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getSurname() {
        return surname;
    }

    public void setSurname(String surname) {
        this.surname = surname;
    }

    public Set<Post> getWrote() {
        return wrote;
    }

    public void setWrote(Set<Post> wrote) {
        this.wrote = wrote;
    }
    
    public abstract String getRole();

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (getId() != null ? getId().hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof SystemUser)) {
            return false;
        }
        SystemUser other = (SystemUser) object;
        if ((this.getId() == null && other.getId() != null) || (this.getId() != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return getName() + " " + getSurname();
    }
}
